<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/css/common.css" media="all">
  <link rel="stylesheet" href="../viewstyle/css/searchform.css">
  <script src="/js/layui/layui.all.js"></script>
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
      <div style="text-align: center;">
        <div class="layui-inline">
          <input class="layui-input" name="id" id="test-table-demoReload" placeholder="输入主题名称" autocomplete="off">
        </div>

        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-admin" id="btnsearch" lay-submit lay-filter="LAY-user-back-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
          </button>
        </div>
      </div>
    </div>



    <div class="layui-card-body">

      <table class="layui-hide" id="themedata" lay-filter="themedata"></table>

    </div>

  </div>
</div>



</body>

<script type="text/html" id="tb">
  <button type="submit" class="layui-btn layui-btn-sm layui-icon layui-icon-add-circle" lay-event="addTheme">新增主题</button>
</script>




<script type="text/html" id="caozuo">
  <input type="submit"  value="编辑"    class="layui-btn " lay-submit="" lay-event="editTheme"/>
  <input type="submit"  value="配置欢迎界面" class="layui-btn " lay-submit="" lay-event="updateWelcome"/>
  <input type="submit"  value="配置桌面"     class="layui-btn " lay-submit="" lay-event="updateTheme"/>
</script>

<script src="/admin/js/token.js"></script>
<script src="/js/jquery-2.2.4.js"></script>
<script>


  layui.use(['form', 'layedit', 'laydate','table'], function(){
    var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
    var table = layui.table;

    table.render({
      elem: "#themedata",
      url: "/admin/theme/query/themeAll?theme_admin=1",
      id: "t",
      toolbar:"#tb",
      cols: [[{
        title: "主题编号",
        field: "theme_id",
        width: "10%",
        align: "center"
      },
        {
          title: "主题名称",
          field: "theme_name",
          width: "20%",
          align: "center"
        }
        ,   {
          title: "主题图片",
          field: "theme_image",
          width: "10%",
          align: "center",
          templet: function(d) {
            return "<img width='50px' height='50px' src='" + IMAGE_SERVER +"/" + d.theme_image + "'></img>";
          }
        }
        ,
        {
          title: "审核状态",
          field: "theme_status",
          class:"as",
          width: "10%",
          align: "center"
        }, {
          title: "admin_id",
          field: "admin_id",
          hide: true
        },
        {
          title: "操作",
          class:"as",
          width: "50%",
          align: "center",
          toolbar:"#caozuo"
        }

      ]],page:{
        curr:1
      },
      limit:40,
      done: function(res, curr, count){
       // localStorage.setItem('page',curr);
        $("#count").html(count);
      }

    })
    table.on('toolbar(themedata)', function (obj) {
     var data = obj.data; //获得当前行数据
      var e = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

      switch (e) {

        case 'addTheme':
          var local_store = layui.data("local_store");
          var local = local_store.token;
          $.ajax({
          url: "/admin/theme/query/guanli/themeAll",
          type: "get",
          success: function (res) {
            console.log(res.data)
            var adminId={
              themeId:res.data[0].admin_id
            }
            $.ajax({
              url:" /admin/theme/add/guanli/theme",
              dataType: "json",
              contentType:"application/json;charset=utf-8",
              type:"post",
              data:JSON.stringify(adminId),
               beforeSend: function(request) {
                  request.setRequestHeader("token", local);
               }
              ,success:function (res) {

                  if(res.code==500){
                    layer.msg("权限不足到别处试试吧",{icom:5,time: 1000})
                  }else{
                    layer.open({
                      title:"新增主题",
                      content:"../station_config/views/layui/addGuanLiTheme.html",
                      type:2,
                      area:["100%","100%"]
                    })
                  }
              },error:function () {

              }

            })
          },
          error:function () {
            layer.msg('网络原因编辑失败',{
              icon:2
            });
          }
        })
          break;
      }
    })


    table.on("tool(themedata)", function (obj) {
      var json = obj.data; //获得当前行数据
      var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
      switch (layEvent) {
        case "updateTheme":
          var url="/screen?id="+json.theme_id+"&station_id="+json.id;
          window.open(url,"_blank");
          break;
        case "updateWelcome":
          var url="/welcome?id="+json.theme_id+"&station_id="+json.id;
          window.open(url,"_blank");
          break;
        case "editTheme":
          localStorage.setItem("themeId",json.theme_id);
          localStorage.setItem("themeName",json.theme_name);
          localStorage.setItem("themeImage",json.theme_image);
          localStorage.setItem("themeStatus",json.theme_status);
          location="/admin/zhuti/themeEdit.html";
          break;

      }
    });
  });





</script>
</html>
